﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.ManageAttrType
{
    public partial class modAttrType : System.Web.UI.Page
    {
        AttributeTypeBLL bll = new AttributeTypeBLL();
        public AttributeType at = new AttributeType();
        public string selsel = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!this.IsPostBack)
            {
                this.bind(int.Parse(Request["id"]));
            }
        }
        void bind(int id)
        {
             at = bll.GetAttributeById(id);
             if (at.outApp.IndexOf("ManagerCategory/CategoryList.aspx?typeId=") > -1)
             {
                 selsel = "-1";
             }
             else if (at.outApp.IndexOf("ManageBaseArt/BaseArtList.aspx") > -1)
             {
                 selsel = "ManageBaseArt/BaseArtList.aspx";
             }
             else if (at.outApp.IndexOf("ManageSingleArt/AddBaseArt.aspx") > -1)
             {
                 selsel = "ManageSingleArt/AddBaseArt.aspx";
             }
             else if (at.outApp.IndexOf("ManageBaseArtDesc/BaseArtList.aspx") > -1)
             {
                 selsel = "ManageBaseArtDesc/BaseArtList.aspx";
             }
             else { selsel = "0"; }
            this.hdfpid.Value  = id.ToString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            int id = int.Parse(this.hdfpid.Value);
            AttributeType at = bll.GetAttributeById(id);
            at.typeName = Request["txtTypeName"].Trim();
            string outapp = Request["selOutType"];
            if (outapp.Equals("0")||outapp.Equals("-1"))
            { outapp = Request["txtOutApp"]; }
            //else if (outapp.Equals("-1"))
            //{
            //    outapp = "ManagerCategory/CategoryList.aspx?typeId=" + Request["txtOutApp"].Trim();
            //}
            
                at.outApp = StringUtil.checkStr(outapp.Trim());
            
            bll.Modify(at);
            string menu = (new ArtTypeBLL()).GetTypeTree();
            FileUtil.WriteToFile(Server.MapPath("/manage/menutext/menu.txt"), menu);

            StringUtil.Alert("修改成功", "AddAttributeType.aspx");
        }
    }
}
